package com.pucong.gitee.database.backup.business.database.controller;

import com.pucong.gitee.database.backup.business.database.service.AutoSearchSqlInfoService;
import com.pucong.gitee.database.backup.common.entity.database.BackupSearchSqlInfo;
import com.pucong.gitee.database.backup.common.entity.database.dto.BackupSearchSqlInfoSaveDto;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2020-06-23
 */
@RestController
@RequestMapping("/backup/searchSqlInfo")
@Api(value = "sql 收藏信息-API ", tags = "sql 收藏信息")
public class AutoSearchSqlInfoController {

    @Autowired
    private AutoSearchSqlInfoService autoSearchSqlInfoService;

    @GetMapping("/getSearchSqlInfoControllerList")
    @ApiOperation(value = "查询sql收藏记录")
    public Res<List<BackupSearchSqlInfo>> getSearchSqlInfoControllerList(){
        List<BackupSearchSqlInfo> backupSearchSqlInfoList = autoSearchSqlInfoService.getSearchSqlInfoControllerList();
        return Res.ok(backupSearchSqlInfoList);
    }

    @GetMapping("/getSearchSqlInfoById/{id}")
    @ApiOperation(value = "根据主键查询")
    public Res<BackupSearchSqlInfo> getExeSqlLogById(@ApiParam("主键")@PathVariable("id") String id){
        BackupSearchSqlInfo backupSearchSqlInfo = autoSearchSqlInfoService.getSearchSqlInfoById(id);
        return Res.ok(backupSearchSqlInfo);
    }

    @PostMapping("/saveInfo")
    @ApiOperation(value = "新增和修改信息")
    public Res<Integer> saveInfo(@Validated @RequestBody BackupSearchSqlInfoSaveDto dto){
        int i = autoSearchSqlInfoService.saveInfo(dto);
        return Res.ok(i);
    }

}
